﻿using VisualWip.Core.Interfaces;

namespace VisualWip.Core.Columns
{
    public abstract class WorkItemsColumnBase : Column
    {
        private IWorkItemSizeStratergy _sizeStratergy;
        private WorkItemSize _workItemSize;

        protected WorkItemsColumnBase()
        {
            _sizeStratergy = new DecresingSizeWorkItemSizeStratergy(new StaticWorkItemSizeProvider());
        }

        public WorkItemSize WorkItemSize
        {
            get { return _workItemSize; }
            set
            {
                if (value != _workItemSize)
                {
                    _workItemSize = value;
                    OnPropertyChanged(this, () => WorkItemSize);
                }
            }
        }

        public IWorkItemSizeStratergy SizeStratergy
        {
            get { return _sizeStratergy; }
            set
            {
                if (value != _sizeStratergy)
                {
                    _sizeStratergy = value;
                    OnPropertyChanged(this, () => SizeStratergy);
                }
            }
        }

        private IQuery _query;
        public IQuery Query
        {
            get { return _query; }
            set
            {
                if (value != _query)
                {
                    _query = value;
                    OnPropertyChanged(this, () => Query);
                }

            }
        }

        public override void Reset()
        {
            base.Reset();
            Query.Reset();
        }
        public override PersistenceTree Persist(string name)
        {
            PersistenceTree settings = base.Persist(name);
            settings.AddChild(() => WorkItemSize);
            settings.AddChild(() => Query);
            return settings;
        }

        public override void Load(PersistenceTree settings)
        {
            base.Load(settings);
            WorkItemSize = settings.GetChild(() => WorkItemSize, new LargeWorkItemSize());
            Query = settings.GetChild(() => Query,"FirstQuery", new NoQuery());
        }
    }
}